package com.cdyx.outsideprescription.util;

import java.util.*;

public class CalendarUtil {
    public static List<Map<String,String>> getYearMoth(){
        Calendar calendar=Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int moth = calendar.get(Calendar.MONTH)+1;
        calendar.add(Calendar.MONTH,-6);
        int year2=calendar.get(Calendar.YEAR);
        int moth2=calendar.get(Calendar.MONTH)+1;
        List<Map<String,String>> mothYear=new LinkedList<>();
        if (year2<year){
            for (; moth2 <=12 ; moth2++) {
                String yearMoth="";
                if (moth2<10){
                    yearMoth=String.valueOf(year2)+"0"+moth2;
                }else {
                    yearMoth=String.valueOf(year2)+moth2;

                }
                Map<String,String> map=new HashMap();
                map.put("year",Integer.toString(year2));
                map.put("month",yearMoth);
                mothYear.add(map);
            }
            for (int i=1;i<=moth;i++){
                String yearMoth="";
                if (i<10){
                    yearMoth=String.valueOf(year)+"0"+i;
                }else {
                    yearMoth=String.valueOf(year)+i;
                }

                Map<String,String> map=new HashMap();
                map.put("year",Integer.toString(year));
                map.put("month",yearMoth);
                mothYear.add(map);
            }
        }else {
            for (; moth2 <= moth; moth2++) {
                String yearMoth="";
                if (moth2<10){
                    yearMoth=String.valueOf(year)+"0"+moth2;
                }else {
                    yearMoth=String.valueOf(year)+moth2;

                }
                Map<String,String> map=new HashMap();
                map.put("year",Integer.toString(year));
                map.put("month",yearMoth);
                mothYear.add(map);
            }
        }
        return mothYear;
    }
}
